From: Christian Korber Date: Mon, 29 Jul 2024 07:39:43 +0000 (+0200) Subject: luci-app-snmpd: add snmp_version and ip_protocol X-Git-Url: http://git.openwrt.org/%22https:/collectd.org//%22http:/www.crowdsec.net/%22/%22https:/collectd.org/%22http:/www.crowdsec.net/%22?a=commitdiff_plain;h=c1f1ba0afd57de06b7982ddc9a178cdb1bdec509;p=project%2Fluci.git luci-app-snmpd: add snmp_version and ip_protocol This commit introduces the variables snmp_version and ip_protocol. These are used in future commits to determine which SNMP version (snmp_version) to use and which port (ip_protocol) is suitable. Signed-off-by: Christian Korber --- diff --git a/applications/luci-app-snmpd/htdocs/luci-static/resources/view/snmpd/snmpd.js b/applications/luci-app-snmpd/htdocs/luci-static/resources/view/snmpd/snmpd.js index 7a65b84730..5d8f6478f5 100644 --- a/applications/luci-app-snmpd/htdocs/luci-static/resources/view/snmpd/snmpd.js +++ b/applications/luci-app-snmpd/htdocs/luci-static/resources/view/snmpd/snmpd.js @@ -2,11 +2,27 @@ // Karl Palsson 2021 'use strict'; 'require form'; +'require uci'; +'require fs'; +'require rpc'; 'require ui'; 'require view'; return L.view.extend({ - render: function() { + load: function() { + return Promise.all([ + uci.load('snmpd'), + ]); + }, + + __init__: function() { + this.super('__init__', arguments); + + this.ip_protocol = null; + this.snmp_version = null; + }, + + render: function(data) { let m, s, o, g, go; m = new form.Map('snmpd', @@ -44,9 +60,55 @@ return L.view.extend({ go.default = '0'; go.rmempty = false; + this.ip_protocol = g.option(form.ListValue, 'ip_protocol', _('IP version')); + this.ip_protocol.value('ipv4', _('Only IPv4')); + this.ip_protocol.value('ipv6', _('Only IPv6')); + this.ip_protocol.value('ipv4/ipv6', _('IPv4 and IPv6')); + this.ip_protocol.optional = false; + this.ip_protocol.forcewrite = true; + this.ip_protocol.default = 'ipv4'; + this.ip_protocol.rmempty = false; + + this.ip_protocol.cfgvalue = function(section_id) { + let ip_protocol = uci.get('snmpd', section_id, 'ip_protocol'); + + if (!ip_protocol) { + const s = uci.get_first('snmpd', 'agent'); + if (!s) + return null; + + const rawAddr = uci.get('snmpd', s['.name'], 'agentaddress'); + if (!rawAddr) + return null; + + const addr = rawAddr.toUpperCase(); + const p = []; + + if (addr.match(/UDP:\d+/g)) + p.push('ipv4'); + + if (addr.match(/UDP6:\d+/g)) + p.push('ipv6'); + + ip_protocol = p.join('/'); + } + + return ip_protocol; + }; + go = g.option(form.Value, 'agentaddress', _('The address the agent should listen on'), _('Eg: UDP:161, or UDP:10.5.4.3:161 to only listen on a given interface')); + this.snmp_version = g.option(form.ListValue, 'snmp_version', + _('SNMP version'), + _('SNMP version used to monitor and control the device')); + this.snmp_version.default = 'v1/v2c'; + this.snmp_version.rmempty = false; + this.snmp_version.forcewrite = true; + this.snmp_version.value('v1/v2c', _('SNMPv1 and SNMPv2c')); + this.snmp_version.value('v1/v2c/v3', _('SNMPv1, SNMPv2c and SNMPv3')); + this.snmp_version.value('v3', _('Only SNMPv3')); + go = g.option(form.Value, 'agentxsocket', _('The address the agent should allow AgentX connections to'), _('This is only necessary if you have subagents using the agentX ' + 'socket protocol. Eg: /var/run/agentx.sock'));